package com.hr.leetcode.贪心算法;

/**
 * @author 周恒哲
 * @date 2020/05/23
 * 思路一：双重遍历，判断前一个比后一个小就记录结果
 **/
public class _122_买卖股票的最佳时机II {
    public static int maxProfit(int[] prices) {
        int result=0;
        int sum=0;
        for (int i = 0; i < prices.length-1; i++) {
                if (prices[i]<prices[i+1]){
                    result=prices[i+1]-prices[i];
                    sum+=result;
                }
        }
        return sum;
    }

    public static void main(String[] args) {
        int[] prices= {7,1,5,3,6,4};
        System.out.println(_122_买卖股票的最佳时机II.maxProfit(prices));
    }
}
